package com.dkm.ec.product.repository.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Repository;

import com.dkm.base.core.helper.SpringHelper;
import com.dkm.base.db.persistence.dao.IQueryDao;
import com.dkm.biz.repository.AbstractRepository;
import com.dkm.ec.product.domain.ProductMedia;
import com.dkm.ec.product.persistence.dao.ProductMediaQueryDao;
import com.dkm.ec.product.persistence.entity.ProductMediaPo;
import com.dkm.ec.product.repository.ProductMediaRepository;

/**
 * 对象功能:产品媒体 Repository接口的实现类
 * 开发公司:SKG.COM
 * 开发人员:颜超敏
 * 创建时间:2014-12-17 17:21:14
 */
@Repository
public class ProductMediaRepositoryImpl extends AbstractRepository<String, ProductMediaPo,ProductMedia> implements ProductMediaRepository{
	  
	@Resource
	private  ProductMediaQueryDao productMediaQueryDao;

	public ProductMedia newInstance() {
		ProductMediaPo po = new ProductMediaPo();
		ProductMedia productMedia = SpringHelper.getBean(ProductMedia.class);
		productMedia.setData(po);
		return productMedia;
	}

	public ProductMedia newInstance(ProductMediaPo po) {
		ProductMedia productMedia = SpringHelper.getBean(ProductMedia.class);
		productMedia.setData(po);
		return productMedia;
	} 
	
	public List<ProductMediaPo> findByProdId(String prodId) {
		return productMediaQueryDao.findByProdId(prodId);
	}

	@Override
	protected IQueryDao<String, ProductMediaPo> getQueryDao() {
		return productMediaQueryDao;
	}
	
	public ProductMediaPo getMainMediaPoByProdId(String prodId){
		return productMediaQueryDao.getMainMediaPoByProdId(prodId);
	}

	@Override
	public ProductMediaPo getMainMediaPoByProdIdAttrOpId(String prodId,
			String attrOpId) {
		
		return  productMediaQueryDao.getMainMediaPoByProdIdAttrOpId(prodId,attrOpId);
	}
	@Override
	public ProductMediaPo getSpecialMediaPoByProdId(String prodId){
		return productMediaQueryDao.getSpecialMediaPoByProdId(prodId);
	}

	@Override
	public ProductMediaPo getSpecialMediaPoByProdIdAttrOpId(String prodId,
			String attrOpId) {
		
		return  productMediaQueryDao.getSpecialMediaPoByProdIdAttrOpId(prodId,attrOpId);
	}
	
	@Override
	public List<ProductMediaPo> findByProdIdForSale(String prodId,String isGallery,String mediaType,String attrOpId) {
		return productMediaQueryDao.findByProdIdForSale(prodId,isGallery,mediaType,attrOpId);
	}

	@Override
	public List<ProductMediaPo> findSaleByProdId(String prodId) {
		return productMediaQueryDao.findSaleByProdId(prodId);
	}

	@Override
	public List<ProductMediaPo> findSpecialMediaPoByProdIdAttrOpId(
			String prodId, String attrOpId) {
		return productMediaQueryDao.findSpecialMediaPoByProdIdAttrOpId(prodId,attrOpId);
	}

	@Override
	public List<ProductMediaPo> findSpecialMediaPoByProdId(String prodId) {
		return productMediaQueryDao.findSpecialMediaPoByProdId(prodId);
	}

	@Override
	public List<ProductMediaPo> findAllByProdIdAndSpecialValue(String prodId,String specialValue) {
		Map<String, Object> params=new HashMap<String, Object>();
		params.put("prodId", prodId);
		params.put("specialValue", specialValue);
		return productMediaQueryDao.findByKey("findAllByProdIdAndSpecialValue", params);
	}

	@Override
	public List<ProductMediaPo> findAllVideoByProdId(String prodId) {
		// TODO Auto-generated method stub
		Map<String, Object> params=new HashMap<String, Object>();
		params.put("prodId", prodId);
		params.put("mediaType", "video");
		return productMediaQueryDao.findByKey("findAllVideoByProdId", params);
	}

	@Override
	public List<ProductMediaPo> findbyProductByColor(String prodEntityId,
			String attrName,String type) {
		Map<String, Object> params=new HashMap<String, Object>();
		params.put("prodId", prodEntityId);
		params.put("attrName",attrName );
		params.put("type",type );
		return   productMediaQueryDao.findByKey("findbyProductByColor", params);
	}
}
